package chixing.day04;

//姓名、年龄、性别、是否结婚
//性别（gender）也可以用M（male）F（female）
public class Person {
    private String personName;
    private int personAge;
    private int personSex;//1男，0女
    private boolean personIsMarriage;

    public Person(){}
    public Person(String personName, int personAge, int personSex, boolean personIsMarriage) {
        this.personName = personName;
        this.personAge = personAge;
        this.personSex = personSex;
        this.personIsMarriage = personIsMarriage;
    }

    /**
     * 判断两个任是否能结婚
     * （1）两人均未婚
     *  （2）必须是异性
     *  （3）男性年龄>=24，女性年龄>=22
     *  满足以上三个条件就可以结婚。
     * @param otherPerson  另一个人的对象
     * @return 返回是否满足结婚条件，满足返回true，不满足返回false
     *
     */
    public boolean canMarry(Person otherPerson){
        //如果第二个为空或者与第一个相同则直接返回false
        if (otherPerson == null || otherPerson == this)
            return false;

        //两个人是否是异性
        if (this.personSex == otherPerson.personSex)
            return false;

        //两个人是否都未婚
        //if(this.personIsMarriage) 等于 if(this.personIsMarriage==true)
        //if(!this.personIsMarriage) 等于 if(this.personIsMarriage==false)
        if (this.personIsMarriage || otherPerson.personIsMarriage)
            return false;

        //男性年龄>=24，女性年龄>=22
        if ( (this.personSex == 1 && this.personAge >=24 && otherPerson.personAge >= 22)
            || (this.personSex == 0 && this.personAge >= 22 && otherPerson.personAge >=24) )
            return true;

        return false;
    }

    public void setPersonName(String personName){
        this.personName = personName;
    }
    public String getPersonName(){
        return this.personName;
    }

    public void setPersonAge(int personAge){
        this.personAge = personAge;
    }
    public int getPersonAge(){
        return this.personAge;
    }

    public void setPersonSex(int personSex){
        this.personSex=personSex;
    }
    public int getPersonSex(){
        return this.personSex;
    }

    public void setpersonIsMarriage(boolean personIsMarriage){
        this.personIsMarriage=personIsMarriage;
    }
    public boolean getpersonIsMarriage(){
        return this.personIsMarriage;
    }

    @Override
    public String toString() {
        return "Person{" +
                "personName='" + personName + '\'' +
                ", personAge=" + personAge +
                ", personSex=" + personSex +
                ", personIsMarriage=" + personIsMarriage +
                '}';
    }

}
